/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pollobeta;

import java.net.*;
import java.io.*;


import java.net.*;
import java.io.*;
import java.util.ArrayList;
import pollobeta.VentanaPolloDraw;


public class ClientePruebaPaint implements Runnable{
	private Socket s;
	private ObjectOutputStream salida;
	private ObjectInputStream entrada;
	private VentanaPolloDraw vc;

	public ClientePruebaPaint(VentanaPolloDraw vc){
		this.vc = vc;

	}

	public void run(){
		try{
			s = new Socket("localhost",9998);
			salida = new ObjectOutputStream(s.getOutputStream());
			entrada = new ObjectInputStream(s.getInputStream());
			vc.chat.getAreaChat().append("Conexion Exitosa");
                        this.leer();

                        }catch(Exception e) {
                            this.cerrar();
                        }


	}

	public void cerrar(){
		try{

			salida.close();
			entrada.close();
			s.close();

		}catch(Exception ex){

		}
	}

	public void escribir(Object s){
		try{
			salida.writeObject(s);

		}catch(Exception ex){

		}
	}

	public void leer(){
		try{
			while(true){
				Object entrada1 = entrada.readObject();
				if(entrada1!=null && entrada1 instanceof String)
					vc.chat.getAreaChat().append("\n"+s.getInetAddress().getHostName()+"dice:"+(String)entrada1);
                                if(entrada1 !=null && entrada1 instanceof ArrayList){
                                    System.out.println("recibi una arraylist de "+((ArrayList)entrada1).size());
                                        vc.paint.diujarExterno((ArrayList)entrada1);
                            }

				Thread.sleep(15);



			}
		}catch(Exception ex){

		}
	}

}